/* a.out coredump register dumper
 *
 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
 * Written by David Howells (dhowells@redhat.com)
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public Licence
 * as published by the Free Software Foundation; either version
 * 2 of the Licence, or (at your option) any later version.
 *
 * Copyright (C) 2009  Hangzhou C-SKY Microsystems co.,ltd.
 */

#ifndef _ASM_A_OUT_CORE_H
#define _ASM_A_OUT_CORE_H

#ifdef __KERNEL__

#include <linux/user.h>
#include <linux/elfcore.h>

/*
 * fill in the user structure for an a.out core dump
 */
static inline void aout_dump_thread(struct pt_regs *regs, struct user *dump)
{
	struct switch_stack *sw;

/* changed the size calculations - should hopefully work better. lbt */
	dump->magic = CMAGIC;
	dump->start_code = 0;
	dump->start_stack = rdusp() & ~(PAGE_SIZE - 1);
	dump->u_tsize = ((unsigned long) current->mm->end_code) >> PAGE_SHIFT;
	dump->u_dsize = ((unsigned long) (current->mm->brk +
					  (PAGE_SIZE-1))) >> PAGE_SHIFT;
	dump->u_dsize -= dump->u_tsize;
	dump->u_ssize = 0;

	if (dump->start_stack < TASK_SIZE)
		dump->u_ssize = ((unsigned long) (TASK_SIZE - 
		                         dump->start_stack)) >> PAGE_SHIFT;

	dump->u_ar0 = offsetof(struct user, regs);
	sw = ((struct switch_stack *)regs) - 1;
	dump->regs.pc = regs->pc;
	dump->regs.r1 = sw->r1;
	dump->regs.syscallr2 = regs->syscallr2
	dump->regs.sr = regs->sr;
	dump->regs.r2 = sw->r2;
	dump->regs.r3 = sw->r3;
	dump->regs.r4 = sw->r4;
	dump->regs.r5 = sw->r5;
	dump->regs.r6 = sw->r6;
	dump->regs.r7 = sw->r7;
	dump->regs.r8 = sw->r8;
	dump->regs.r9 = sw->r9;
	dump->regs.r10 = sw->r10;
	dump->regs.r11 = sw->r11;
	dump->regs.r12 = sw->r12;
	dump->regs.r13 = sw->r13;
	dump->regs.r14 = sw->r14;
	dump->regs.r15 = sw->r15;
	
	/* dump floating point stuff */
	dump->u_fpvalid = dump_fpu (regs, &dump->ckcorefp);
}

#endif /* __KERNEL__ */
#endif /* _ASM_A_OUT_CORE_H */
